/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jboss.seam.example.booking.entityquery;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.jbpm.JbpmContext;


/**
 *
 * @author RHO
 */
@AutoCreate
@Name("myRoleTaskQuery")
@Scope(ScopeType.EVENT)
@Restrict("#{identity.loggedIn}")
public class MyRoleTaskQuery {
	
	@In
	private JbpmContext jbpmContext;
	
	@Out(value = "myTasksQuery", required=false)
	List<TaskInstance> groupTaskListFound = new ArrayList<TaskInstance>();
	
	@SuppressWarnings("unchecked")
	@Factory(value = "myTasksQuery")
	public void collectMyTask() {
		
		List<String> actorIds = new ArrayList<String>();
		
		actorIds.add("admin");
		
		groupTaskListFound = jbpmContext.getGroupTaskList(actorIds);
		if(groupTaskListFound.size() > 0){
			for(TaskInstance taskInstance : groupTaskListFound){
				TaskInstance firstTaskInstance = taskInstance;
				ProcessInstance processInstance = firstTaskInstance.getProcessInstance();
				jbpmContext.save(processInstance);
			}
		}
	}
	
}

